package model.dominio;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.Table;
import model.dao.DaoBase;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "Motorista") 
public class Motorista extends Pessoa {
    
    @Column(length = 45)
    private String cnh;

    public Motorista() {
    }

    public Motorista(String nome, String cpf, String cnh) {
        super(nome, cpf);
        this.cnh = cnh;
    }

    public Motorista(String nome, String cpf, String telefone, String endereco, String cnh) {
        super(nome, cpf, telefone, endereco);
        this.cnh = cnh;
    }
    
    /**
     * @return the cnh
     */
    public String getCnh() {
        return cnh;
    }

    /**
     * @param cnh the cnh to set
     */
    public void setCnh(String cnh) {
        this.cnh = cnh;
    }
    
    @PostPersist
    public void gerarLogCad() {
        Logg logg = new Logg();
        logg.setCodigo_objeto(super.getCodigo());
        logg.setAcao(new AcaoSistema(20));
        logg.setData_hora(super.getData_ultima_alteracao());
        logg.setUsuario(super.getUsuario());
        new DaoBase().salvar(logg);
    }

    @PostUpdate
    public void gerarLogAlt() {
        Logg logg = new Logg();
        logg.setCodigo_objeto(this.getCodigo());
        logg.setAcao(new AcaoSistema(21));
        logg.setData_hora(this.getData_ultima_alteracao());
        logg.setUsuario(this.getUsuario());
        new DaoBase().salvar(logg);
    }

}
